package com.dense.kuiniu.shelfcard.business;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.dense.kuiniu.shelfcard.R;
import com.dense.kuiniu.shelfcard.base.BaseFragment;
import com.dense.kuiniu.shelfcard.entity.BindInfo;
import com.dense.kuiniu.shelfcard.utils.timer.CountDownView;
import com.dense.kuiniu.shelfcard.utils.timer.CounterController;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author Administrator
 * @date 2020/9/23
 */
public class CardOutputInfoDelegate extends BaseFragment {
    private static final String KEY = "info";

    public static CardOutputInfoDelegate getInstance(BindInfo info) {
        Bundle bundle = new Bundle();
        bundle.putParcelable(KEY, info);
        CardOutputInfoDelegate delegate = new CardOutputInfoDelegate();
        delegate.setArguments(bundle);
        return delegate;
    }

    @BindView(R.id.tv_info)
    TextView mTvInfo;
    @BindView(R.id.view_count_down)
    CountDownView mCountDownView;
    private BindInfo mBindInfo;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null) {
            mBindInfo = bundle.getParcelable(KEY);
        }
    }

    @Override
    protected int getLayoutRes() {
        return R.layout.delegate_card_output_info;
    }

    @OnClick({R.id.tv_confirm})
    public void onClick(View view) {
        super.onClick(view);
    }

    @Override
    protected void onClick2(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.tv_confirm:
                pop();
                break;
        }
    }

    @Override
    protected void init() {
        mCountDownView.start(new CounterController.OnCompleteListener() {
            @Override
            public void onComplete() {
                pop();
            }
        });
        mTvInfo.setText(R.string.text_bind_card_info);
        mTvInfo.append("\n");
        mTvInfo.append(getString(R.string.text_user_name) + mBindInfo.getFkReaderName());
        mTvInfo.append("\n");
        mTvInfo.append(getString(R.string.text_card_no) + mBindInfo.getCardNumber());
    }
}